package com.neusoft.neuiotms.dcom.model.insurance;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.InsuranceTaskStatus;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@Table(name = "neuiot_insurance_register_task")
@org.hibernate.annotations.Table(appliesTo = "neuiot_insurance_register_task", comment = "重保服务登记任务表")
public class InsuranceRegisterTask extends AbstractAuditModel {

    private static final long serialVersionUID = -3906639778715864095L;

    /** 服务编码 */
    @NotBlank(message = "服务编码")
    @Length(max = 255, message = "服务编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '服务编码'")
    private String registerCode;

    /** 单位编码 */
    @NotBlank(message = "单位编码不能为空")
    @Length(max = 255, message = "单位编码不能超过{max}位")
    @Column(length = 255)
    @Comment("varchar(255) NOT NULL COMMENT '单位编码'")
    private String unitCode;

    /** 单位名称 */
    @NotBlank(message = "单位名称不能为空")
    @Length(max = 255, message = "单位名称不能超过{max}位")
    @Column(length = 255)
    @Comment("varchar(255) NOT NULL COMMENT '单位名称'")
    private String unitName;

    /** 服务开始时间 */
    @Column(nullable = true)
    private Date startTime;

    /** 服务结束时间 */
    @Column(nullable = true)
    private Date endTime;

    /** 服务备注 */
    @Lob
    @Column(columnDefinition = "text")
    @Comment("text COMMENT '服务备注'")
    private String registerRemarks;

    /** 任务编码 */
    @NotBlank(message = "任务编码 ")
    @Length(max = 255, message = "任务编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '任务编码 '")
    private String code;

    /** 完成状态 */
    @Enumerated(EnumType.STRING)
    @Column(length = 32, nullable = false)
    @Comment("varchar(32) NOT NULL COMMENT '完成状态'")
    private InsuranceTaskStatus status = InsuranceTaskStatus.pending;

    /** 关联服务登记 */
    @ManyToOne
    private InsuranceRegister insuranceRegister;

    /** 关联重保服务巡检任务表 */
    @OneToMany(mappedBy = "registerTask", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<InsuranceInspectionTask> inspectionTask = new ArrayList<>();

    /** 关联重保服务每日上报任务表 */
    @OneToMany(mappedBy = "registerTask", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<InsuranceReportTask> reportTask = new ArrayList<>();

    /** 关联重保服务服务总结任务表 */
    @OneToMany(mappedBy = "registerTask", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<InsuranceSummaryTask> summaryTask = new ArrayList<>();

}
